package com.imooc.web.filter;

import org.springframework.stereotype.Component;

import javax.servlet.*;
import java.io.IOException;
import java.util.Date;

@Component
public class TimeUsingFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("time Filter init");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        long time = new Date().getTime();
        filterChain.doFilter(servletRequest,servletResponse);
        long endTime = new Date().getTime();
        long usingTime = endTime-time;

        System.out.println("请求使用了"+usingTime+"ms");
    }

    @Override
    public void destroy() {
        System.out.println("time Filter destroy");

    }
}
